package com.shuzijun.leetcode.editor.cn;
public class MaximumSubarray{
    public static void main(String[] args) {
         Solution solution = new MaximumSubarray().new Solution();
         solution.maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4});
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int maxSubArray(int[] nums) {
        int n = nums.length;
        int maxValue = Integer.MIN_VALUE;
        int sum  = 0;
        for (int i = 0; i < n; i++) {
            if (sum < 0){
                sum = 0;
            }
            sum += nums[i];
            if (sum > maxValue){
                maxValue =sum;
            }
        }
        return maxValue;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}